﻿package mortal.game.view.signUp.renderer
{
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.manager.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.signUp.data.*;
    import mortal.game.view.signUp.util.*;

    public class SignUpDateCellRenderer extends GCellRenderer
    {
        private var _cellBg:GBitmap;
        private var _dayNum:GTextFiled;
        private var _imgGou:GBitmap;
        private var _faceSpr:ToolTipSprite;
        private var _imgFace:GBitmap;
        private var _imgHasSignUp:GBitmap;
        private var _imgToday:GBitmap;
        private var _signUpBtn:GLoadingButton;
        private var _resignUpBtn:GLoadingButton;
        private var _signUpArrow:SWFPlayer;
        private var _signUpData:SignUpDateCellData;

        public function SignUpDateCellRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._cellBg = UIFactory.gBitmap("", 0, 0, this);
            this._dayNum = UIFactory.gTextField("", 11 - 3, 5 - 6, 20, 20, this);
            this._imgGou = UIFactory.gBitmap("", 33, 5, this);
            this._faceSpr = UICompomentPool.getUICompoment(ToolTipSprite);
            this._faceSpr.x = 39;
            this._faceSpr.y = 7;
            this.addChild(this._faceSpr);
            this._faceSpr.toolTipData = this.getTipData();
            this._imgFace = UIFactory.gBitmap("", 0, 0, this._faceSpr);
            this._imgHasSignUp = UIFactory.gBitmap("", 11, 2, this);
            this._imgToday = UIFactory.gBitmap("", 72, 0, this);
            this._signUpBtn = UIFactory.gLoadingButton(ResFileConst.SignUpBtn, 29 - 8, 19 - 4, 53, 27, this);
            this._resignUpBtn = UIFactory.gLoadingButton(ResFileConst.ReSignUpBtn, 29 - 8, 19 - 4, 53, 27, this);
            this._signUpBtn.configEventListener(MouseEvent.CLICK, this.onSignUpHandler);
            this._resignUpBtn.configEventListener(MouseEvent.CLICK, this.onSignUpHandler);
            this._signUpArrow = UICompomentPool.getUICompoment(SWFPlayer);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:int = 0;
            var _loc_3:Date = null;
            super.data = param1;
            this.clear();
            if (param1 is SignUpDateCellData)
            {
                this._signUpData = param1 as SignUpDateCellData;
                this._cellBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.SignUpCellLight);
                this._dayNum.text = this._signUpData.signDay + "";
                _loc_2 = int(ClockManager.instance.nowDate.date);
                if (this._signUpData.signDay < _loc_2)
                {
                    if (this._signUpData.hasSignUp)
                    {
                        this._imgGou.bitmapData = GlobalClass.getBitmapData(ImagesConst.Icon_Right);
                    }
                    else if (this._signUpData.isCanReSignUp)
                    {
                        this._signUpBtn.visible = false;
                        this._resignUpBtn.visible = true;
                        EffectManager.glowFilterReg(this._signUpBtn);
                    }
                    else
                    {
                        _loc_3 = new Date();
                        _loc_3.date = this._signUpData.signDay;
                        if (SignUpUtil.isBeforeOpenServerDate(_loc_3) || SignUpUtil.isBeforeCreateRoleDate(_loc_3))
                        {
                            this._imgFace.bitmapData = null;
                        }
                        else
                        {
                            this._imgFace.bitmapData = GlobalClass.getBitmapData(ImagesConst.Icon_CryFace);
                        }
                    }
                }
                else if (this._signUpData.signDay == _loc_2)
                {
                    this._imgToday.bitmapData = GlobalClass.getBitmapData(ImagesConst.Icon_Today);
                    if (this._signUpData.hasSignUp)
                    {
                        this._imgHasSignUp.bitmapData = GlobalClass.getBitmapData(ImagesConst.Icon_HasSignUp);
                    }
                    else if (this._signUpData.isCanSignUp)
                    {
                        this._signUpBtn.visible = true;
                        this._resignUpBtn.visible = false;
                        EffectManager.glowFilterReg(this._signUpBtn);
                        this.addArrow();
                    }
                }
            }
            else
            {
                this._cellBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.SignUpCellDark);
            }
            return;
        }// end function

        private function addArrow() : void
        {
            this._signUpArrow.timeRate = 2;
            this._signUpArrow.scaleY = 0.8;
            this._signUpArrow.load("guideArrow.swf", ModelType.NormalSwf, null);
            this._signUpArrow.move(this._signUpBtn.x - 10, this._signUpBtn.y + 13);
            this.addChild(this._signUpArrow);
            return;
        }// end function

        private function removeArrow() : void
        {
            DisplayUtil.removeMe(this._signUpArrow);
            return;
        }// end function

        private function onSignUpHandler(event:MouseEvent) : void
        {
            var e:* = event;
            var signUpDay:* = this._signUpData.isToday ? (0) : (this._signUpData.signDay);
            GameProxy.checkIn.setCheckIn(signUpDay);
            var roleLevel:* = Cache.instance.role.entityInfo.level;
            if (!(SignUpUtil.isSignUpAvailable() || SignUpUtil.hasRewardToTake()) && roleLevel < (GameConst.SignUpOpenLevel + 1))
            {
                var closeWin:* = function () : void
            {
                GameController.signUp.view.hide();
                return;
            }// end function
            ;
                setTimeout(closeWin, 500);
            }
            return;
        }// end function

        private function getTipData() : String
        {
            var _loc_1:* = Language.getString(41376);
            return _loc_1;
        }// end function

        private function clear() : void
        {
            EffectManager.glowFilterUnReg(this._signUpBtn);
            this.removeArrow();
            this._dayNum.text = "";
            this._cellBg.bitmapData = null;
            this._imgGou.bitmapData = null;
            this._imgFace.bitmapData = null;
            this._imgHasSignUp.bitmapData = null;
            this._imgToday.bitmapData = null;
            this._signUpBtn.visible = false;
            this._resignUpBtn.visible = false;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._cellBg.dispose(param1);
            this._dayNum.dispose(param1);
            this._imgGou.dispose(param1);
            this._imgFace.dispose(param1);
            this._imgHasSignUp.dispose(param1);
            this._imgToday.dispose(param1);
            this._signUpBtn.dispose(param1);
            this._faceSpr.dispose(param1);
            this._signUpArrow.dispose();
            this._resignUpBtn.dispose();
            this._cellBg = null;
            this._dayNum = null;
            this._imgGou = null;
            this._imgFace = null;
            this._imgToday = null;
            this._imgHasSignUp = null;
            this._signUpBtn = null;
            this._faceSpr = null;
            this._signUpArrow = null;
            this._resignUpBtn = null;
            this._signUpData = null;
            return;
        }// end function

    }
}
